import { Toast } from 'vant'
import { playSuccess, playError } from '@ve/eventTask/actions/pda/audio/webAudio.js'

import { iswap } from '@ve/utils/pdaUtils'
// import Vue from 'vue'
class $CIMC$ {
  constructor() {
    this.$ = window.CIMC || {}
  }
  hasFun(name) {
    if (!this.$[name]) {
      this.$[name] = () => {
        console.log('name', name)
      }
    }
  }

  // 声音弹出提示
  // playMusic(type) {
  //   console.log('type', type)
  //   this.$.playMusic(type, '')
  // }

  // 声音弹出提示
  playMusic(type, msg) {
    if (msg) {
      Toast(msg)
    }

    if (iswap() == 'WEB') {
      type == 'OK' ? playSuccess() : playError()
    } else {
      return this.$.playMusic(type, '')
    }
  }

  // 获取本机mac地址
  getMacAddress(cb) {
    this.$.getMacAddress('GETMACADDRESS')
    window.GETMACADDRESS = (data) => cb && cb(data) //回调
  }

  // 连接蓝牙打印
  connectBlueToothPrint(callback, cpclStr) {
    this.$.connectBlueToothPrint(callback, cpclStr)
  }
  // 蓝牙打印
  printByBlueTooth(str) {
    this.$.printByBlueTooth(str, 'BLUEPRINT')
  }
  // 图片上传打开摄像头
  choosePic() {
    this.$.choosePic('UPLOADPIC')
  }
  // 清除ip缓存
  delIpMsg() {
    return this.$.delIpMsg('DELLIP')
  }
  //获取是否更新标识 + 版本号
  isUpgrade(cb) {
    this.$.isUpgrade('GETISUPGRADE')
    window.GETISUPGRADE = (data) => cb && cb(data) //回调
  }
  //打开手机摄像头
  openCapture(cb) {
    this.$.openCapture('GETOPENCAPTURE')
    window.GETOPENCAPTURE = (data) => cb && cb(data)
  }
  // 清除ip缓存
  hideBoard() {
    return this.$.hideBoard()
  }
  //RFID点亮，熄灭(西门子)
  UHFRead(callBack, type, traceIdArr) {
    this.$.UHFRead(callBack, type, traceIdArr)
    //window.UHFREAD = (data) => cb && cb(data) //回调
  }

  // 识别方法
  ocrRecognite(callBack) {
    window.OCR_RECOGNITE = (data) => callBack && callBack(data)
    this.$.ocrRecognite('OCR_RECOGNITE')
  }
}

export default new Proxy(new $CIMC$(), {
  get(target, key) {
    target.hasFun(key)
    return target[key]
  },
})

// class MyBridge {
//   fnList = {}
//   on(name, data) {
//     return new Promise((resolve) => {
//       if (this.fnList[name]) {
//         this.emit(name, data)
//       } else {
//         this.fnList[name] = (res) => {
//           resolve(res);
//         }
//         window[name] = this.fnList[name];
//         this.emit(name, data);
//       }
//     })
//   }
//   emit(name, data) {
//     window[name].call(null, data)
//   }
// }

// Vue.prototype.myBridge = new MyBridge()
